package http;

import model.ApiConfigDataModel;
import model.ApiDataModel;
import tool.DataReplace;

import java.util.Map;

/**
 * Created by yangxianming on 2015-06-10.
 */
public class PackageNormalData implements PackageDataImpl {
    ApiDataModel adm = null;
    ApiConfigDataModel acdm = null;

    PackageNormalData(ApiDataModel adm, ApiConfigDataModel acdm){
        this.adm = adm;
        this.acdm = acdm;
    }

    @Override
    public Object packageData() {
        String requestData = "";
        boolean first = true;
        for (Map.Entry<String, String> me:adm.parameters.entrySet()){
            String k = me.getKey();
            String v = me.getValue();
            v = DataReplace.replace(acdm, v);
            me.setValue(v);     //将替换后的数据放回对象

            if (first){
                requestData = k + "=" + v;
                first = false;
                continue;
            }
            requestData = requestData + "&" + k + "=" + v;
        }

        return requestData;
    }
}
